package utils;

import java.util.HashMap;

import org.apache.log4j.Logger;

public class LoagCfg
{
	protected String[] args;
	protected HashMap<String, String> argsMap = new HashMap<String, String>();
	protected static Logger log = Logger.getRootLogger();

	public LoagCfg(String[] args)
	{
		this.args=args;
		log = Logger.getRootLogger();
	}

	public void process() throws Exception
	{
		System.out.println("Parsing args");
		for(String line : args){
			String[] parts = line.split("=");
			if(parts.length!=2)
				throw new Exception("Bad Arguments Format");
			argsMap.put(parts[0], parts[1]);
		}
		System.out.println("args readed: "+argsMap.size() );		
	}

	public String getString(String label) throws Exception{
		if(argsMap.get(label)==null)
			throw new Exception("no value for lable["+label+"]");
		return argsMap.get(label);	
	}
	

	public String getString(String label, String defaultValue) throws Exception{
		if(argsMap.get(label)==null)
			return defaultValue;
		return argsMap.get(label);	
	}

	public int getInteger(String label, int defaultValue)
	{
		if(argsMap.get(label)==null)
			return defaultValue;
		return Integer.parseInt(argsMap.get(label));
	}

}
